<template>
  <div class="AddStaff">
    <h5>编辑VIP</h5>
    <div class="ele-title">
      <span>{{ vipLevelName }}</span>
    </div>
    <div class="ele-form" style="margin-top: 40px;">
      <el-row>
        <el-form ref="form" :model="BindForm" :rules="rules" label-width="80px">
          <el-form-item label="等级名称" prop="vipName">
            <el-col :span="10">
              <el-input v-model="BindForm.vipName" />
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-col :span="10">
              <el-alert
                title="显示在用户端的会员等级名称。"
                type="info"
                :closable="false"
              />
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submit">提交</el-button>
            <el-button type="primary" @click="returnPage">返回上一页</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
import { modifyVipLevel } from '@/api/customAPI/shop/vipManage'

/** 编辑会员等级 */
export default {
  name: 'AddMember',
  data() {
    return {
      loading: false,
      vipLevelName: null,
      BindForm: {
        id: null,
        vipName: ''
      },
      rules: {
        vipName: [{ required: true, message: '请输入等级名称', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    /** 初始化*/
    init() {
      const params = this.$dd(this.$route.query.p)
      this.vipLevelName = params.row.vipLevelName
      this.BindForm.id = params.row.id
      if (params.row.vipName != '————') {
        this.BindForm.vipName = params.row.vipName
      }
    },

    /** 返回上一页*/
    returnPage() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    },

    /** 提交 */
    submit() {
      this.$refs.form.validate(v => {
        if (v) {
          const data = this.$XEUtils.clone(this.BindForm, true)
          modifyVipLevel(data).then(res => {
            this.$message.success('修改会员等级成功')
            this.$store.dispatch('tagsView/delView', this.$route)
            this.$router.go(-1)
          }).catch(err => {
            console.log(err)
          })
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>
.AddStaff {
  padding: 50px 100px;
  .ele-title {
    height: 50px;
    line-height: 50px;
    background: #f3f3f3;
    border-radius: 5px;
    padding-left: 20px;
  }
  /*.ele-form {
    margin-top: 30px;
    ::v-deep.el-form {
      .el-form-item__label {
        width: 100px;
        text-align: start;
      }
      !*.el-form-item__error {
        margin-left: 0;
      }*!
    }
  }*/
}
</style>
